﻿using Synergy.dbmodel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Synergy
{
    public partial class Form快递单号回写发货单 : Form
    {
        public Form快递单号回写发货单()
        {
            InitializeComponent();
        }

        private void button回写_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxU8单号.Text) == true)
            {
                label3.Text = "U8单号不能为空";
                return;
            } 
            if (string.IsNullOrEmpty(textBox快递单号.Text) == true)
            {
                label3.Text = "快递单号不能为空";
                return;
            }
            //DispatchList
            DispatchList d = SqlSugarHelp.scope.Queryable<DispatchList>().Where(it => it.cDLCode == textBoxU8单号.Text).First(); 
            if (d == null)
            {
                label3.Text = $"U8单号{textBoxU8单号.Text}不存在";
                return;
            }
            else
            {
                d.cDefine1 = textBox快递单号.Text.Trim();
                int r = SqlSugarHelp.scope.Updateable(d).UpdateColumns(it => new { it.cDefine1 }).WhereColumns(it => new { it.DLID,it.cDLCode }).ExecuteCommand();
                if (r > 0) 
                {
                    label3.Text = $"回写成功"+DateTime.Now.ToShortTimeString();
                    textBoxU8单号.Text = "";
                    textBox快递单号.Text = "";
                    textBoxU8单号.Focus();
                    return;
                }
                else
                {
                    label3.Text = $"回写失败" + DateTime.Now.ToShortTimeString();
                    return;
                }
            }
        }
    }
}
